package cn.sylinx.horm.example.section14;

import java.io.Serializable;
import java.util.List;

import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import cn.sylinx.horm.core.SqlClient;
import cn.sylinx.horm.dialect.fs.FS;

@Profile("section14")
@Component
public class Section14 implements CommandLineRunner {

    private SqlClient sqlClient;

    public Section14(SqlClient sqlClient) {
        this.sqlClient = sqlClient;
    }

    @Override
    public void run(String... args) throws Exception {
        testAttrMapping();
        testUnderLineMapping();
    }

    void testUnderLineMapping() {

        // 创建对象
        MyExample14_1 my = new MyExample14_1();
        my.setFieldName("field_name");
        my.setFieldNumber("field_number");
        Serializable pk = sqlClient.save(my);
        System.out.println("save pk -> " + pk);

        // 查询
        List<MyExample14_1> dataList = sqlClient.query(FS.of(MyExample14_1.class));
        System.out.println("dataList ->" + dataList);
    }

    void testAttrMapping() {

        // 创建对象
        MyExample14 my = new MyExample14();
        my.setFieldName("field_name");
        my.setFieldNumber("field_number");
        Serializable pk = sqlClient.save(my);
        System.out.println("save pk -> " + pk);

        // 查询
        List<MyExample14> dataList = sqlClient.query(FS.of(MyExample14.class));
        System.out.println("dataList ->" + dataList);
    }
}
